/*     */ package org.wltea.analyzer.lucene;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import org.apache.lucene.analysis.Tokenizer;
/*     */ import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
/*     */ import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
/*     */ import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
/*     */ import org.wltea.analyzer.core.IKSegmenter;
/*     */ import org.wltea.analyzer.core.Lexeme;
/*     */ 
/*     */ public final class IKTokenizer extends Tokenizer
/*     */ {
/*     */   private IKSegmenter _IKImplement;
/*     */   private final CharTermAttribute termAtt;
/*     */   private final OffsetAttribute offsetAtt;
/*     */   private final TypeAttribute typeAtt;
/*     */   private int endPosition;
/*     */ 
/*     */   public IKTokenizer(boolean useSmart)
/*     */   {
/*  62 */     this.offsetAtt = ((OffsetAttribute)addAttribute(OffsetAttribute.class));
/*  63 */     this.termAtt = ((CharTermAttribute)addAttribute(CharTermAttribute.class));
/*  64 */     this.typeAtt = ((TypeAttribute)addAttribute(TypeAttribute.class));
/*  65 */     this._IKImplement = new IKSegmenter(this.input, useSmart);
/*     */   }
/*     */ 
/*     */   public boolean incrementToken()
/*     */     throws IOException
/*     */   {
/*  74 */     clearAttributes();
/*  75 */     Lexeme nextLexeme = this._IKImplement.next();
/*  76 */     if (nextLexeme != null)
/*     */     {
/*  79 */       this.termAtt.append(nextLexeme.getLexemeText());
/*     */ 
/*  81 */       this.termAtt.setLength(nextLexeme.getLength());
/*     */ 
/*  83 */       this.offsetAtt.setOffset(nextLexeme.getBeginPosition(), nextLexeme.getEndPosition());
/*     */ 
/*  85 */       this.endPosition = nextLexeme.getEndPosition();
/*     */ 
/*  87 */       this.typeAtt.setType(nextLexeme.getLexemeTypeString());
/*     */ 
/*  89 */       return true;
/*     */     }
/*     */ 
/*  92 */     return false;
/*     */   }
/*     */ 
/*     */   public void reset()
/*     */     throws IOException
/*     */   {
/* 101 */     super.reset();
/* 102 */     this._IKImplement.reset(this.input);
/*     */   }
/*     */ 
/*     */   public final void end()
/*     */   {
/* 108 */     int finalOffset = correctOffset(this.endPosition);
/* 109 */     this.offsetAtt.setOffset(finalOffset, finalOffset);
/*     */   }
/*     */ }

/* Location:           D:\tools\IKAnalyzer2012_V5.jar
 * Qualified Name:     org.wltea.analyzer.lucene.IKTokenizer
 * JD-Core Version:    0.6.0
 */